{extend name="public:layout" /}
{block name="title"}{$moudleName}列表{/block}
{block name="head"}
<script src="/public/plugins/tableExport.jquery.plugin/tableExport.min.js"></script>
	<style>
		.leave_layer p {height: 40px;line-height: 40px;}
        .alert{margin-bottom:0px;}
        .check .check-span{margin-right:10px;}
    </style>
{/block}
{block name="body"}
<div class="wrapper wrapper-content">
    <div class="ibox">
        <div class="ibox-title">
            <ol class="breadcrumb">
                <ol class="breadcrumb">
                    <li class="active"><i class="fa fa-hand-o-right"></i> {$moudleName}列表</li>
                </ol>
            </ol>
            <span class="pull-right">
                <span class="label" style="background:#caebfb">已完成</span>
                <span class="label" style="background:#c9e7c9">正在进行</span>
                <span class="label" style="background:#ffe8d6">即将开始</span>
                <span class="label"><span class="fa fa-exclamation-triangle" style="color:#ff0000;"></span>异常</span>
            </span>
            <div class="clearfix"></div>
        </div>
        <div class="ibox-content">
            <div class="toolbar">
                <button type="button" class="btn btn-primary"
                        onClick ="$('#grid').tableExport({ type: 'excel', escape: 'false' })">数据导出</button>
                <form class="form-inline" id="searchForm" method="post">
                    <div class="form-group">
                        <select name="car_status" class="form-control" onchange="refresh();">
                            <option value="-1">全部订单</option>
                            <option value="0">待确认订单</option>
                            <option value="1">正在出车订单</option>
                            <option value="2">已收车订单</option>
                            <option value="3">已结算订单</option>
                            <option value="4">欠款订单</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <input type="text" name="btype_id" id="select-btype_id" placeholder="请选择客户" data-init="" style="width:100%;" />
                        <script>
                            In('selectpage',function(){
                                var dom=$('#select-btype_id');
                                dom.selectPage({
                                    keyField:'aid',
                                    showField:'title',
                                    multiple:false,
                                    pagination:true,
                                    dbTable:'car_btype',
                                    data:'/plus/ajax/selectpage',
                                    andOr:'OR',
                                    params : function(){return {'searchField':'title'}},
                                    eAjaxSuccess : function(data){
                                        if(data.totalRow>0){
                                            return data;
                                        }else{
                                            return false;
                                        }
                                    }
                                });
                            })
                        </script>
                    </div>
                    <div class="form-group">
                        <input class="form-control" type="text" placeholder="请输入车牌号" name="car_sn" />
                    </div>
                    <div class="form-group">
                        <input class="form-control" type="text" placeholder="请输入司机姓名" name="fleet_driver" />
                    </div>
                    <div class="form-group">
                        <input class="form-control" name="rangdate" id="rangdate" type="text" value="{$rangdate}" placeholder="日期范围">
                    </div>
                    <div class="form-group">
                        <input class="form-control" type="text" id="order_start_adress" placeholder="请输入起点" name="order_start_adress" />
                    </div>
                    <div class="form-group">
                        <input class="form-control" type="text" id="order_end_adress" placeholder="请输入终点" name="order_end_adress" />
                    </div>
                    <button type="button" class="btn btn-info" onclick="refresh()"><i class="fa fa-search"></i> 搜索</button>
                    <a class="btn btn-white" href="{:url('index',['mid'=>$Request.param.mid,'tpl'=>'static_order'])}">
                        <i class="fa fa-trash"></i> 清空
                    </a>
                </form>
            </div>
            <div id="buttons">
                <span class="text-danger" id="statics"> </span>
            </div>
            <table class="table table-bordered" id="grid"></table>
        </div>
    </div>
</div>
{/block}
{block name="script"}
<script type="text/javascript">
    var is_mobile="{:is_mobile()}";
    var cardView=false;
    if(is_mobile==1){
        cardView=true;
    }
    $(function () {
        //列定义
        var columnsData=[
            {field: 'aid', title: '编号',width:'50',sortable:true},
            {field: 'title', title: '行程',
                formatter:function (value,row,index) {
                    var html='';
                    html+='<strong class="text-danger">车辆:'+row.car_sn+'</strong><br/>';
                    html+= row.order_start_time.substring(5,16)+'至'+row.order_end_time.substring(5,16)+'<br/>';
                    html+='<strong class="text-info">'+row.order_start_adress+'-'+row.order_end_adress+'</strong><br/>';
                    html+='驾驶员:'+row.fleet_driver+'<br/>';
                    return html;
                }
             },
            {field:'order_l',title:'加油升数',sortable:true,
                footerFormatter: function (value) {
                    var count = 0;
                    for (var i in value) {
                        count += parseFloat(value[i].order_l);
                    }
                    return count.toFixed(2);
                }
            },
            {field: 'order_charge', title: '订单金额',width:100,sortable:true,
                footerFormatter: function (value) {
                    var count = 0;
                    for (var i in value) {
                        count += parseFloat(value[i].order_charge);
                    }
                    return count.toFixed(2);
                }
            },
            {field: 'order_advance', title: '订金',width:80,sortable:true,
                footerFormatter: function (value) {
                    var count = 0;
                    for (var i in value) {
                        count += parseFloat(value[i].order_advance);
                    }
                    return count.toFixed(2);
                }
            },
            {field: 'order_pay', title: '已收款',width:100,sortable:true,
                footerFormatter: function (value) {
                    var count = 0;
                    for (var i in value) {
                        count += parseFloat(value[i].order_pay);
                    }
                    return count.toFixed(2);
                }
            },
            {field: 'order_q', title: '待收款',width:80,sortable:true,
                footerFormatter: function (value) {
                    var count = 0;
                    for (var i in value) {
                        count += parseFloat(value[i].order_q);
                    }
                    return count.toFixed(2);
                }
            },
            {field: 'discount_money', title: '优惠金额',width:80,sortable:true,
                footerFormatter: function (value) {
                    var count = 0;
                    for (var i in value) {
                        count += parseFloat(value[i].discount_money);
                    }
                    return count.toFixed(2);
                }
            },
            /*
            {field: 'order_driver_wages', title: '司机工资',width:100,
                footerFormatter: function (value) {
                    var count = 0;
                    for (var i in value) {
                        count += parseFloat(value[i].order_driver_wages);
                    }
                    return count.toFixed(2);
                }
            },
            */
            {field: 'sj_pre_money', title: '司机借款',width:80,sortable:true,
                footerFormatter: function (value) {
                    var count = 0;
                    for (var i in value) {
                        count += parseFloat(value[i].sj_pre_money);
                    }
                    return count.toFixed(2);
                }
            },
            {field: 'order_stop', title: '停车费',width:80,sortable:true,
                footerFormatter: function (value) {
                    var count = 0;
                    for (var i in value) {
                        count += parseFloat(value[i].order_stop);
                    }
                    return count.toFixed(2);
                }
            },
            {field: 'order_fuel', title: '加油费',width:80,sortable:true,
                footerFormatter: function (value) {
                    var count = 0;
                    for (var i in value) {
                        count += parseFloat(value[i].order_fuel);
                    }
                    return count.toFixed(2);
                }
            },
            {field: 'order_tolls', title: '过路费',width:80,sortable:true,
                footerFormatter: function (value) {
                    var count = 0;
                    for (var i in value) {
                        count += parseFloat(value[i].order_tolls);
                    }
                    return count.toFixed(2);
                }
            },
            {field: 'order_eat', title: '食宿费',width:80,sortable:true,
                footerFormatter: function (value) {
                    var count = 0;
                    for (var i in value) {
                        count += parseFloat(value[i].order_eat);
                    }
                    return count.toFixed(2);
                }
            },
            {field: 'order_other', title: '其他费用',width:80,sortable:true,
                footerFormatter: function (value) {
                    var count = 0;
                    for (var i in value) {
                        count += parseFloat(value[i].order_other);
                    }
                    return count.toFixed(2);
                }
            },
            {field: 'order_bala', title: '结余费用',width:100,sortable:true,
                footerFormatter: function (value) {
                    var count = 0;
                    for (var i in value) {
                        count += parseFloat(value[i].order_bala);
                    }
                    return count.toFixed(2);
                }
            }
        ];
        In('btable', function () {
            $('#grid').bootstrapTable({
                showColumns:true,
                url: '__URL__/pagelist.html?mid={$Request.param.mid}',
                cardView:cardView,
                height:'600',
                toolbar:'#buttons',
                sortName:'aid',
                sortOrder:'desc',
                method:'post',
                pagination:true,
                queryParamsType:'page',
                sidePagination:'server',
                pageSize: 50,                       //每页的记录行数（*）
                pageList: [50, 100, 200, 500, 1000],        //可供选择的每页的行数（*）
                showRefresh:true, //显示刷新按钮
                showToggle:true, //显示切换视图按钮
                showPaginationSwitch:true, //显示数据条数选择框
                idField:'aid', //主键列
                clickToSelect:true, //设置true 将在点击行时，自动选择rediobox 和 checkbox
                singleSelect:false, //设置true 将禁止多选
                maintainSelected:true, //设置为true 将记住选择项
                queryParams:function (params) {
                    params.op="{$Request.param.op}";
                    params.car_sn=$("input[name='car_sn']").val();
                    params.car_status=$("select[name='car_status']").val();
                    params.fleet_driver=$("input[name='fleet_driver']").val();
                    params.rangdate=$("#rangdate").val();
                    params.order_start_adress=$("#order_start_adress").val();
                    params.order_end_adress=$("#order_end_adress").val();
                    params.btype_id = $('#select-btype_id').val();
                    return params;
                },
                columns: columnsData,
                rowStyle:function rowStyle(row, index) {
                    if(row.car_status==0){ //出车中
                        return { css: { "background": "#ffe8d6","color":"#333" } };
                    }
                    if(row.car_status==1){ //出车中
                        return { css: { "background": "#c9e7c9","color":"#333" } };
                    }
                    if(row.car_status==2){ //已完成
                        return { css: { "background": "#caebfb","color":"#333" } };
                    }
                    return { };
                },
                onLoadSuccess:function (data) {
                    var statics=data.statics;
                    var html='';
                    if(statics.total_order_count>0){
                        html+=" 行程单数量:"+statics.total_order_count+'笔';
                    }
                    if(statics.total_order_count>0){
                        html+=" 总里程:"+statics.total_order_charge+'公里';
                    }
                    if(statics.total_order_count>0){
                        html+=" 总加油升数:"+statics.total_order_l;
                    }
                    if(statics.total_order_charge>0){
                        html+=" 订单总金额:"+statics.total_order_charge+'元';
                    }
                    if(statics.calc_total_order_pay>0){
                        html+=" 已付款金额:"+statics.calc_total_order_pay+'元';
                    }
                    if(statics.total_order_advance>0){
                        html+=" 欠款金额:"+statics.calc_total_q+'元';
                    }
                    $('#statics').html(html);
                },
                showFooter: true,
                showExport: true,
                exportDataType: "basic"
            });
        });
    });
    //刷新表格
    function refresh() {
        $('#grid').bootstrapTable('refresh');
    }
    //检索日期
    In('laydate',function () {
        laydate.render({
            elem: '#rangdate',
            range: '~'
        });
    })
</script>
{/block}